<?php
	/** sous fonctionnalité de gestion d'une équipe
	 * @author Sebastian Mosser
	 */

class sfTeamStats extends aSubFeature {

	public function __construct() {
		  $this->_acl = new AccessControlList(); 
      $this->_acl->setGranted(1); // Entraineur
      $this->_acl->setGranted(2); // Recrutement
      $this->_acl->setGranted(3); // Secretariat
      $this->_acl->setGranted(7); // SysAdmin
		}
		
	public function check() {
	
		$idTeam = PropRetriever::getProp($_POST,"teamId");
		$perm = $this->_acl->isExposable(Login::getGroups());
		
		try {
			$aTeam = Team::read($idTeam);
		}
		catch(Exception $e) {
			$page = "<h1>Une erreur fatale est survenue ! </h1><br /> <br />"; 
			$page .= "<div align=\"center\"> <span class=\"error\">";
			$page .= 
					"L'équipe d'identifiant Balloon <code>[$idTeam]</code> n'éxiste pas!";
			return $page;
		}

		return True;
	
	}

	protected function run() {
		// Test d'accès		
		$test = $this->check();
		if ($test !== True)
			return $test;
			
		$idTeam    = PropRetriever::getProp($_POST,"teamId");	
		$aTeam = Team::read($idTeam);
		return $this->displayForm($aTeam,$idTeam);
	}



	private function displayForm($aTeam,$idTeam) {

		$teamName = $aTeam->displayShort();

		$type = PropRetriever::getProp($_POST,"type");		
		$type = ($type == "" ? 1: $type);
		$availablesTypes = Matche::getTypeAsList($type);

		$displayTitle = Matche::$MATCHE_TYPE[$type];
		
		// On calcule les stats
		$result = TeamStatMaker::process($aTeam,$type);
		
		// On génère les affichages
		
		$page = "<h1> $teamName : Statistiques ${displayTitle}</h1>";
		$page .= fManageTeams::getReturnButton($idTeam);
		$page  .= <<<EOS
<h2> Critère de calcul </h2>
<div align="center" >
<form method="post" accept-charset="utf-8">
    <fieldset>
      <legend>Compétition</legend>
      <br />
      <label>
        <span> Type de Match : </span>
        <select name="type" class="edit">
          ${availablesTypes}
        </select> &nbsp; &nbsp;
      </label>
      <br />
      <input type="hidden" name="action" value="compute" />
      <input type="hidden" name="teamId" value="${idTeam}" />
      <input type="submit" name="valid"  value="Valider" class="button" />
    </fieldset>
    </form>
</div>

${result}

EOS;
		return $page;
	}
	

	
}

?>